//
//  CunQuDetailHeaderView.m
//  ProjectforHDX
//
//  Created by yinda on 2018/6/5.
//  Copyright © 2018年 H.DX. All rights reserved.
//

#import "CunQuDetailHeaderView.h"
#define   HEADER_HEIGHT 60
#define   GAP 5
#define   LEFT_GAP 15
#define DEL_FontSize 13
#define DEL_LABEL_HEIGHT 21
@implementation CunQuDetailHeaderView


-(id)initHeaderViewWithOrderStatusDic:(NSDictionary*)orderStatusDic AndReceiverDict:(NSDictionary *)receiverDict AndlogisticsDict:(NSDictionary *)logisticsDcit AndOrderTypeInfoDict:(NSDictionary *)orderTypeInfoDict{
    self=[super initWithFrame:CGRectMake(0, 0, BOUNDSWIDTH, HEADER_HEIGHT * 4)];
    self.backgroundColor = [UIColor whiteColor];
    
    self.orderStatusDic = [[NSMutableDictionary alloc]initWithDictionary:orderStatusDic];
    if (receiverDict && [receiverDict isKindOfClass:[NSDictionary class]]) {
        self.receiverDict = [[NSMutableDictionary alloc]initWithDictionary:receiverDict];
    }
    self.logisticsDcit = [[NSMutableDictionary alloc]initWithDictionary:logisticsDcit];
    self.orderTypeInfoDict = [[NSMutableDictionary alloc]initWithDictionary:orderTypeInfoDict];
    [self UIConfig];
    return self;
}

- (void)UIConfig{
    
    //订单UI＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝
    UIView *orderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, HEADER_HEIGHT + 5)];
    orderView.backgroundColor = SYSTEM_COLOR;
    //订单号
    RZCustomLable *orderCodeTitleLabel=[[RZCustomLable alloc] init];
    [orderCodeTitleLabel setFont:[UIFont systemFontOfSize:13]];
    [orderCodeTitleLabel setTextColor:[UIColor whiteColor] ];
    [orderView addSubview:orderCodeTitleLabel];
    if ([[self.orderStatusDic objectForKey:@"cunqutype"]isEqualToString:@"1"]) {
        orderCodeTitleLabel.text = [NSString stringWithFormat:@"%@：%@",[THMangerTool language:@"main.qujianCode"],[self.orderStatusDic objectForKey:@"orderCode"]];
    }
    else{
    orderCodeTitleLabel.text = [NSString stringWithFormat:@"%@：%@",[THMangerTool language:@"main.cunjianCode"],[self.orderStatusDic objectForKey:@"orderCode"]];
    }
    [orderCodeTitleLabel setFrame:CGRectMake(LEFT_GAP, 15, self.width - LEFT_GAP, 21)];
    [orderCodeTitleLabel sizeToFit];
    
    //下单时间
    RZCustomLable *orderTimeLable = [[RZCustomLable alloc]init];
    [orderTimeLable setFont:[UIFont systemFontOfSize:13]];
    [orderTimeLable setTextColor:[UIColor whiteColor] ];
    [orderView addSubview:orderTimeLable];
    if ([[self.orderStatusDic objectForKey:@"cunqutype"]isEqualToString:@"1"]) {
        orderTimeLable.text = [NSString stringWithFormat:@"%@：%@",[THMangerTool language:@"main.qujiantime"],[self.orderStatusDic objectForKey:@"orderTime"]];
    }
    else{
    orderTimeLable.text = [NSString stringWithFormat:@"%@：%@",[THMangerTool language:@"order.cunjiantime"],[self.orderStatusDic objectForKey:@"orderTime"]];
    }
    [orderTimeLable setFrame:CGRectMake(LEFT_GAP, orderCodeTitleLabel.bottom + GAP, self.width-15, 21)];
    [orderTimeLable sizeToFit];
    
    NSString *type = [NSString stringWithFormat:@"%@",[self.orderTypeInfoDict objectForKey:@"orderType"]];
    
    
    //客户订单时间
    RZCustomLable *customerOrderTimeLabel = [[RZCustomLable alloc]init];
    [customerOrderTimeLabel setFont:[UIFont systemFontOfSize:13]];
    [customerOrderTimeLabel setTextColor:[UIColor whiteColor] ];
    customerOrderTimeLabel.text = [NSString stringWithFormat:@"%@：%@",[THMangerTool language:@"order.customer.time"],[self.orderStatusDic objectForKey:@"customerOrderTime"]];
    [customerOrderTimeLabel setFrame:CGRectMake(LEFT_GAP, orderTimeLable.bottom + GAP, self.width-15, 21)];
    [customerOrderTimeLabel sizeToFit];
    
    if ([type isEqualToString:@"9"]) {
        [orderView addSubview:customerOrderTimeLabel];
        [orderView setHeight:HEADER_HEIGHT + 20];
    }
    
    [self addSubview:orderView];
    
//    //订单状态
//    RZCustomLable *statusLab = [[RZCustomLable alloc]init];
//    [statusLab setTextAlignment:NSTextAlignmentCenter];
//    [statusLab setTextColor:[UIColor whiteColor]];
//    [statusLab setFrame:CGRectMake(self.width - 70, 8, 50, 50)];
//    [statusLab setText:[self.orderStatusDic objectForKey:@"statusName"]];
//    statusLab.layer.cornerRadius = 25;
//    statusLab.font = [UIFont systemFontOfSize:13];
//    statusLab.clipsToBounds = YES;
//    [self addSubview:statusLab];
    
    UIImageView *cunjianimageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.width - 70, 8, 50, 50)];
    cunjianimageView.image = [UIImage imageNamed:@"订单"];
    [self addSubview:cunjianimageView];
    
    
    //客户UI
    UIView *receiverView = [[UIView alloc]initWithFrame:CGRectMake(0,  orderView.bottom, self.width, HEADER_HEIGHT)];
    
    //图标
    RZCustomImageView *rightIcon=[[RZCustomImageView alloc] initWithFrame:CGRectMake(GAP*2, receiverView.height /2 - 10, 20, 20)];
    UIImage *image=BDFILEIMAGENAEM(@"Order/img_location");
    [rightIcon setImage:image];
    rightIcon.size = image.size;
    [receiverView addSubview:rightIcon];
    
    //姓名和电话
    RZCustomLable *nameAndTelLabel = [[RZCustomLable alloc] init];
    [nameAndTelLabel setFont:CustomFont(DEL_FontSize)];
    [receiverView addSubview:nameAndTelLabel];
    [nameAndTelLabel setFrame:CGRectMake(30+GAP, GAP + 3, (self.width-rightIcon.width)/2, DEL_LABEL_HEIGHT)];
    [nameAndTelLabel setText:[NSString stringWithFormat:@"%@",[self.receiverDict objectForKey:@"receiverName"]]];
    [nameAndTelLabel setTextColor:[UIColor darkGrayColor]];
    if (nameAndTelLabel.height < DEL_LABEL_HEIGHT) {
        nameAndTelLabel.height = DEL_LABEL_HEIGHT;
    }
    
    //日期
    RZCustomLable *labDate=[[RZCustomLable alloc] init];
    [labDate setFont:CustomFont(10)];
    [labDate setTextColor:[UtilCheck hexStringToColor:@"9d9fa1" alpha:1] ];
    [receiverView addSubview:labDate];
    [labDate setFrame:CGRectMake(nameAndTelLabel.right, GAP + 3 , (self.width-rightIcon.width)/2, DEL_LABEL_HEIGHT)];
    labDate.text=[self.receiverDict objectForKey:@"arriveTime"];
    labDate.numberOfLines=1;
    [labDate sizeToFit];
    if (labDate.height < DEL_LABEL_HEIGHT) {
        labDate.height = DEL_LABEL_HEIGHT;
    }
    
    //是否加急
    RZCustomLable *fastLab=[[RZCustomLable alloc] init];
    [fastLab setFont:CustomFont(10)];
    [fastLab setTextColor:[UIColor redColor] ];
    [receiverView addSubview:fastLab];
    [fastLab setFrame:CGRectMake(nameAndTelLabel.right, GAP + 3 , self.width/2 - rightIcon.width*2, DEL_LABEL_HEIGHT)];
    NSString *htmlString = [self.receiverDict objectForKey:@"xParama"];
    NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    fastLab.attributedText = attrStr;
    fastLab.textAlignment = NSTextAlignmentRight;
    fastLab.numberOfLines=1;
    //        [fastLab sizeToFit];
    if (fastLab.height < DEL_LABEL_HEIGHT) {
        fastLab.height = DEL_LABEL_HEIGHT;
    }
    
    //地址
    RZCustomLable *labAddress=[[RZCustomLable alloc] init];
    [labAddress setFont:CustomFont(DEL_FontSize)];
    [labAddress setTextColor:[UIColor darkGrayColor] ];
    [receiverView addSubview:labAddress];
    [labAddress setFrame:CGRectMake(30+GAP , nameAndTelLabel.bottom + GAP - 4, self.width - rightIcon.width - 30 , 42)];
    labAddress.text=[NSString stringWithFormat:@"%@",[self.receiverDict objectForKey:@"receiverAddress"]];
    labAddress.numberOfLines=0;
    [labAddress sizeToFit];
    if (labAddress.height < DEL_LABEL_HEIGHT) {
        labAddress.height = DEL_LABEL_HEIGHT;
    }
    
    [receiverView setFrame:CGRectMake(0, orderView.bottom, self.width, GAP + nameAndTelLabel.height + labAddress.height + GAP + GAP +GAP)];
    
    [self setFrame:CGRectMake(0, 0, self.width, HEADER_HEIGHT + receiverView.height)];
    [self addSubview:receiverView];
    
    
    
    
    //订单类型UI========================
    UIView *orderTypeView = [[UIView alloc]initWithFrame:CGRectMake(0, receiverView.bottom, self.width, 20)];
    [orderTypeView setBackgroundColor:[Toolobject getColorByRGB:244 green:248 blue:251 alpha:1]];
    
    
    //订单类型
    RZCustomLable *orderTypeLab = [[RZCustomLable alloc] init];
    [orderTypeLab setFont:CustomFont(DEL_FontSize)];
    [orderTypeView addSubview:orderTypeLab];
//    [orderTypeLab setFrame:CGRectMake(16, GAP, self.width/2, DEL_LABEL_HEIGHT)];
    NSString *typeName = @"";
    
    if ([type isEqualToString:@"1"]) {
        typeName = [THMangerTool language:@"orderlist.type.management"];
    }
    else if ([type isEqualToString:@"2"]){
        typeName = [THMangerTool language:@"orderlist.type.replace"];
    }
    else if ([type isEqualToString:@"3"]){
        typeName = [THMangerTool language:@"orderlist.type.repair"];
    }
    else if ([type isEqualToString:@"4"]){
        typeName = [THMangerTool language:@"orderlist.type.test"];
    }
    else if ([type isEqualToString:@"5"]){
        typeName = [THMangerTool language:@"orderlist.type.To borrow"];
    }
    else if ([type isEqualToString:@"6"]){
        typeName = [THMangerTool language:@"orderlist.type.The cargo"];
    }
    else if ([type isEqualToString:@"7"]){
        typeName = [THMangerTool language:@"orderlist.type.Replace delivery"];
    }
    else if ([type isEqualToString:@"8"]){
        typeName = [THMangerTool language:@"orderlist.type.Failure parts"];
    }
    else if ([type isEqualToString:@"9"]){
        typeName = [THMangerTool language:@"orderlist.type.procurement"];
    }
    else if ([type isEqualToString:@"10"]){
        typeName = [THMangerTool language:@"orderlist.type.replenishment"];
    }
    else if ([type isEqualToString:@"11"]){
        typeName = [THMangerTool language:@"orderlist.type.scrap"];
    }else{
        typeName = [THMangerTool language:@"orderlist.type.servers data error"];
    }
    
    [orderTypeLab setText:[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"orderlist.type.Order type"],typeName]];
    [orderTypeLab setTextColor:[UIColor darkGrayColor]];
    if (nameAndTelLabel.height < DEL_LABEL_HEIGHT) {
        nameAndTelLabel.height = DEL_LABEL_HEIGHT;
    }
    
    //仓库
    RZCustomLable *storeNameLab = [[RZCustomLable alloc] init];
    [storeNameLab setFont:CustomFont(DEL_FontSize)];
    [orderTypeView addSubview:storeNameLab];
//    [storeNameLab setFrame:CGRectMake(self.width/2, GAP, self.width/2, DEL_LABEL_HEIGHT)];
    [storeNameLab setText:[NSString stringWithFormat:@"%@：%@", [THMangerTool language:@"delivery.warehouse"],[self.orderTypeInfoDict objectForKey:@"storeName"]]];
    
    //调出库
    RZCustomLable *outStoreNameLab = [[RZCustomLable alloc] init];
    [outStoreNameLab setFont:CustomFont(DEL_FontSize)];
    [orderTypeView addSubview:outStoreNameLab];
//    [outStoreNameLab setFrame:CGRectMake(16, GAP + orderTypeLab.bottom, self.width/2, DEL_LABEL_HEIGHT)];
    [outStoreNameLab setText:[NSString stringWithFormat:@"调出库: %@",[self.orderTypeInfoDict objectForKey:@"outStoreName"]]];
    
    //联系人
    RZCustomLable *contactLab = [[RZCustomLable alloc] init];
    [contactLab setFont:CustomFont(DEL_FontSize)];
    [orderTypeView addSubview:contactLab];
//    [contactLab setFrame:CGRectMake(self.width/2, GAP + orderTypeLab.bottom, self.width/2, DEL_LABEL_HEIGHT)];
    [contactLab setText:[self.orderTypeInfoDict objectForKey:@"contact"]];
    
    //地址
    RZCustomLable *addressLab = [[RZCustomLable alloc] init];
    [addressLab setFont:CustomFont(DEL_FontSize)];
    [orderTypeView addSubview:addressLab];
//    [addressLab setFrame:CGRectMake(16, GAP + outStoreNameLab.bottom, self.width/2, DEL_LABEL_HEIGHT)];
    [addressLab setText:[NSString stringWithFormat:@"地址:%@", [self.orderTypeInfoDict objectForKey:@"address"]]];
    
    if ([type isEqualToString:@"3"]) {
        outStoreNameLab.hidden = YES;
        contactLab.hidden = YES;
        addressLab.hidden = YES;
//        [orderTypeView setFrame:CGRectMake(0, receiverView.bottom, self.width, GAP * 2 + DEL_LABEL_HEIGHT)];
        
    }
    else if ([type isEqualToString:@"6"]) {
        storeNameLab.hidden = YES;
//        [orderTypeView setFrame:CGRectMake(0, receiverView.bottom, self.width, 85)];
        
    }
    else{
        storeNameLab.hidden = YES;
        outStoreNameLab.hidden = YES;
        contactLab.hidden = YES;
        addressLab.hidden = YES;
//        [orderTypeView setFrame:CGRectMake(0, receiverView.bottom, self.width, GAP * 2 + DEL_LABEL_HEIGHT)];
    }
    [self setFrame:CGRectMake(0, 0, self.width, orderTypeView.bottom)];
    
    
    [self addSubview:orderTypeView];
    
    
    
}

@end
